<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      ref="crud"
      v-model="form"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuLeft">
        <el-button type="warning" size="small" icon="el-icon-download" @click="$refs.exportComp.visible = true">导出</el-button>
      </template>
      <template slot="menuRight">
        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
      </template>
    </avue-crud>
    <export-comp ref="exportComp" page-api-url="mes-warehouse/inbound-record/page" :option="option" :page="page" :query="query" file-name="入库记录"></export-comp>
  </basic-container>
</template>

<script>
import userTableConfig from '@/components/user-table-config';
import userConfig from '@/mixins/userConfig';
import { getList } from '@/api/warehouse/warehousingRecords';
import { mapGetters } from 'vuex';
import exportComp from '@/components/export-comp';
export default {
  name: 'warehousingRecords',
  components: {
    userTableConfig,
    exportComp
  },
  mixins: [userConfig()],
  mounted() {
    this.$nextTick(() => {
      //搜索与表格结构分隔
      this.$structuralSplit();
    });
  },
  computed: {
    ...mapGetters(['permission'])
  },
  data() {
    return {
      data: [],
      query: {},
      loading: true,
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      option: {
        height: 'calc(100vh - 485px)',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 5,
        border: true,
        index: true,
        indexLabel: '序号',
        menu: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        columnBtn: false,
        column: [
          {
            label: '入库单号',
            prop: 'inboundOrderNo'
          },
          {
            label: '单据号',
            prop: 'purchaseOrderNo',
            search: true,
            searchOrder: 2
          },
          {
            label: '行号',
            prop: 'purchaseOrderLot'
          },
          {
            label: '供应商',
            prop: 'vendorName',
            search: true,
            searchOrder: 5
          },
          {
            label: '品牌',
            prop: 'partBrand'
          },
          {
            label: '物料编码',
            prop: 'partNo',
            search: true,
            searchOrder: 3
          },
          {
            label: '物料型号',
            prop: 'partModel',
            search: true,
            searchOrder: 4
          },

          {
            label: '入库数量',
            prop: 'inboundQuantity'
          },
          {
            label: '单位',
            prop: 'uom'
          },
          {
            label: '操作人',
            prop: 'inboundByName'
          },
          {
            label: '入库时间',
            prop: 'inboundTime',
            search: true,
            searchOrder: 1,
            searchType: 'datetimerange',
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss',
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间'
          },
          {
            label: '内部批次',
            prop: 'lotNo'
          },
          {
            label: '供应商批次',
            prop: 'vendorLotNo'
          },
          {
            label: '备注',
            prop: 'remark'
          }
        ]
      },
      detailOption: {
        height: 'auto',
        calcHeight: 30,
        dialogWidth: 950,
        tip: false,
        searchShow: true,
        searchMenuSpan: 5,
        border: true,
        index: true,
        indexLabel: '序号',
        menu: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        column: [
          {
            label: '包装条码',
            prop: 'packNo'
          },
          {
            label: '储位编码',
            prop: 'areaCode'
          },
          {
            label: '储位名称',
            prop: 'areaName'
          },
          {
            label: '生产日期',
            prop: 'vendorDate'
          },
          {
            label: '是否尾箱',
            prop: 'isTailBox',
            type: 'select',
            dicData: [
              {
                label: '否',
                value: false
              },
              {
                label: '是',
                value: true
              }
            ]
          },
          {
            label: '数量',
            prop: 'quantity'
          },
          {
            label: '状态',
            prop: 'packingStatus'
          }
        ]
      }
    };
  },
  methods: {
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      if (params.inboundTime && params.inboundTime.length > 0) {
        params.startTime = params.inboundTime[0];
        params.endTime = params.inboundTime[1];
        delete params.inboundTime;
      }
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },

    async onLoad(page, params = {}) {
      this.loading = true;
      try {
        const res = await getList(page.currentPage, page.pageSize, Object.assign(params, this.query));
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
      } catch (e) {
        console.warn(e);
      } finally {
        this.loading = false;
      }
    }
  }
};
</script>

<style scoped></style>
